<template>
  <tab-bar></tab-bar>
  <div class="login-content">
    <el-card>
      <h2 class="text-center pt-[30px]">迷夜综合客服系统</h2>
      <el-form class="w-[380px] pt-[50px] px-[40px]" size="large">
        <el-form-item>
          <el-input placeholder="请输入账号" v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            placeholder="请输入密码"
            v-model="form.password"
            type="password"
            @keyup.enter="login"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            :loading="loading"
            class="w-full"
            type="primary"
            @click="login"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
      <div class="flex items-center justify-end pr-[40px]">
        <el-checkbox v-model="savePassowrd"></el-checkbox>
        <span class="ml-[5px] text-[14px] text-[var(--el-text-color-regular)]"
          >记住密码</span
        >
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
const router = useRouter();
const userStore = useUserStore();

const form = ref(userStore.getAccount());
const savePassowrd = ref(!!form.value.password);

const loading = ref(false);
const login = async () => {
  const { data } = await usePost('/v1/cust/login', form.value, loading);
  userStore.setUserInfo(data);
  if (savePassowrd.value) {
    userStore.setAccount(form.value.username, form.value.password);
  } else {
    userStore.setAccount('', '');
  }
  router.push('/home');
};
</script>

<style lang="scss">
.login-content {
  background-color: antiquewhite;
  background-image: url('/background.png');
  height: calc(100vh - 31px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
</style>
